package template.datasource.druid;

import com.alibaba.druid.pool.DruidDataSourceFactory;

import javax.sql.DataSource;
import java.io.InputStream;
import java.sql.Connection;
import java.util.Properties;

/**
 * Druid演示
 */
public class Demo01 {
    public static void main(String[] args) throws Exception {
        //1.导入jar包(一共两个)
        //2.定义配置文件(格式一定要正确)
        //3.加载配置文件
        Properties pp=new Properties();
        InputStream is = Demo01.class.getClassLoader().getResourceAsStream("druid.properties");//若放在其他地方就需要写完整路径了

        pp.load(is);
        //获取连接池对象
        DataSource ds =DruidDataSourceFactory.createDataSource(pp);
        //获取连接对象
        Connection con = ds.getConnection();

        System.out.println(con);
    }
}
